package com.fengmi.controller;

import com.fengmi.dto.EntityDTO;
import com.fengmi.entity.MallGoodsCat;
import com.fengmi.service.MallGoodsCatService;
import com.fengmi.vo.CatCascaderVO;
import com.fengmi.vo.InfoResult;
import com.fengmi.vo.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Author: 施俊豪
 * Date: 2022/1/22 22:49
 * Note: 商品分类控制器层
 */
@RequestMapping("cat")
@Api(description="商品分类控制器层")
@CrossOrigin
@RestController
public class MallGoodsCatController {

    @Autowired
    private MallGoodsCatService mallGoodsCatService;

    @ApiOperation("分页+条件查询商品分类和商品模板")
    @RequestMapping("/findCatAndTemp")
    public PageResult findCatAndTemp(@ApiParam("查询条件") @RequestBody EntityDTO<Long> entityDTO,
                                     @RequestHeader("token")String token) {
        System.out.println("查询商品分类和模板的token" + token);
        return mallGoodsCatService.findCatAndTemp(entityDTO);
    }

    @ApiOperation("根据父类ID查询分类")
    @RequestMapping("/findCats/{catParent}")
    public InfoResult findCats(@ApiParam(value="父类分类ID",example = "0") @PathVariable("catParent") Long  catParent){
        //System.out.println(catParent);
        return mallGoodsCatService.findCats(catParent);
    }

    @ApiOperation("添加商品分类")
    @RequestMapping("/insertCat")
    public InfoResult insertCat(@ApiParam("添加信息")@RequestBody MallGoodsCat cat){
        return mallGoodsCatService.insertCat(cat);
    }

    @ApiOperation("根据ID查询商品分类")
    @RequestMapping("/findCatById/{id}")
    public InfoResult findCatById(@ApiParam(value="查询条件",example = "0")@PathVariable("id")Long id){
        return mallGoodsCatService.findCatById(id);
    }

    @ApiOperation("修改商品分类")
    @PutMapping("/updateCat")
    public InfoResult updateCat(@ApiParam("修改信息")@RequestBody MallGoodsCat cat){
        return mallGoodsCatService.updateCat(cat);
    }

    @ApiOperation("级联查询商品分类")
    @RequestMapping("/findCatCascader")
    public InfoResult<List<CatCascaderVO>> findCatCascader(){
        return mallGoodsCatService.findCatCascader();
    }
}
